﻿using StarPizza.Model.BaseModel;
using StarPizza.Model.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StarPizza.ViewModel.ManagerSystem
{
    abstract class IngredientAdministrator : INotifyPropertyChanged
    {
        protected StarDataDataContext db;
        protected StockHandler stockHandler;

        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private int editedCost;
        public int EditedCost
        {
            get { return editedCost; }
            set
            {
                if (value != editedCost)
                {
                    editedCost = value;
                    OnPropertyChanged("EditedCost");
                }
            }
        }

        private int editedPrice;
        public int EditedPrice
        {
            get { return editedPrice; }
            set
            {
                if (value != editedPrice)
                {
                    editedPrice = value;
                    OnPropertyChanged("EditedPrice");
                }
            }
        }

        private int newCost;
        public int NewCost
        {
            get { return newCost; }
            set
            {
                if (value != newCost)
                {
                    newCost = value;
                    OnPropertyChanged("NewCost");
                }
            }
        }

        private int newPrice;
        public int NewPrice
        {
            get { return newPrice; }
            set
            {
                if (value != newPrice)
                {
                    newPrice = value;
                    OnPropertyChanged("NewPrice");
                }
            }
        }

        public int supplyAmount;
        public int SupplyAmount
        {
            get { return supplyAmount; }
            set
            {
                if (value != supplyAmount)
                {
                    supplyAmount = value;
                    OnPropertyChanged("SupplyAmount");
                    OnPropertyChanged("SupplyCost");
                }
            }
        }

        protected abstract int ActualCost { get; }
        protected abstract int ActualPrice { get; }
        public int SupplyCost
        {
            get { return SupplyAmount * ActualCost; }
        }

        public IngredientAdministrator(StarDataDataContext db, StockHandler stockHandler)
        {
            this.db = db;
            this.stockHandler = stockHandler;
        }
        protected void IngredientSelected()
        {
            OnPropertyChanged("SupplyCost");
            EditedPrice = ActualPrice;
            EditedCost = ActualCost;
        }
        protected void IngredientUpdated()
        {
            OnPropertyChanged("SupplyCost");
        }
    }
}
